/*
 * Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.
 * Copyright 2016-2017, 2024 NXP
 * All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include "fsl_device_registers.h"
#include "fsl_debug_console.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "board.h"

//#include "arm_cmse.h"
/*******************************************************************************
 * Definitions
 ******************************************************************************/


/*******************************************************************************
 * Prototypes
 ******************************************************************************/

/*******************************************************************************
 * Variables
 ******************************************************************************/

/*******************************************************************************
 * Code
 ******************************************************************************/
/*!
 * @brief Main function
 */

uint32_t NextJump;
#define TZM_IS_NONSECURE_CALLED __attribute__((cmse_nonsecure_call))
/* typedef for non-secure callback functions */
typedef void (*funcptr_ns)(void) TZM_IS_NONSECURE_CALLED;
typedef void (*funcptr_ns)(void) TZM_IS_NONSECURE_CALLED;
int main(void)
{
    char ch;

    /* Init board hardware. */
    BOARD_InitPins();
    BOARD_BootClockRUN();
    BOARD_InitDebugConsole();


    NextJump = *(uint32_t *)(0x00010000);
//    NextJump = 0x00020000;
    PRINTF("I am bootloader\r\n");
    PRINTF("NextJump:%08X\r\n",NextJump);

    /* Set non-secure main stack (MSP_NS) */
    __set_MSP(*((uint32_t *)(NextJump)));

    /* Set non-secure vector table */
    SCB->VTOR = NextJump;
    funcptr_ns ResetHandler_ns;
    /* Get non-secure reset handler */
    ResetHandler_ns = (funcptr_ns)(*((uint32_t *)((NextJump) + 4U)));
    ResetHandler_ns();
    while (1)
    {

    }
}
